package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcxw.hxzbapi.dao.mapper.IncomeUnionDetailMapper;
import com.lcxw.hxzbapi.entity.pojo.IncomeUnionDetail;
import com.lcxw.hxzbcommon.common.StringUtil;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class IncomeUnionDetailService {

    @Resource
    IncomeUnionDetailMapper incomeUnionDetailMapper;

    public IncomeUnionDetail selectById(int id) {
        return incomeUnionDetailMapper.selectById(id);
    }

    public int insert(IncomeUnionDetail incomeUnionDetail) {
        return incomeUnionDetailMapper.insert(incomeUnionDetail);
    }

    public int updateById(IncomeUnionDetail incomeUnionDetail) {
        return incomeUnionDetailMapper.updateById(incomeUnionDetail);
    }

    public IPage<IncomeUnionDetail> selectList(int unionId, String term, Long userId, String status,
        int pageNum,
        int pageSize) {

        IPage<IncomeUnionDetail> page = new Page<>(pageNum, pageSize);
        QueryWrapper<IncomeUnionDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("unionId", unionId);
        wrapper.eq(!StringUtil.isEmpty(term), "term", term);
        wrapper.eq(userId != null, "userId", userId);
        wrapper.eq(!StringUtil.isEmpty(status), "status", status);

        return incomeUnionDetailMapper.selectPage(page, wrapper);
    }
}
